$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'edu/attendance/record',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id',hidden: true, width: 30, key: true },

            { label: '课程名称', name: 'cname', width: 60 },
            { label: '授课班级', name: 'bnames', width: 40 },
            { label: '上课日期', name: 'date', width: 40 },
            { label: '上课时间', name: 'sksj', width: 40 },
            { label: '总人数', name: 'renshu', width: 20 },

            { label: '出勤率', name: 'cql', width: 20 }

        ],
        viewrecords: true,
        height: 385,
        rowNum: 50,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        coptions:[],
        boptions:[],
        joptions:[{'sksj':'1-2','value':'1-2节'},{'sksj':'3-4','value':'3-4节'},{'sksj':'5-6','value':'5-6节'},{'sksj':'7-8','value':'7-8节'},{'sksj':'9-10','value':'9-10节'}],
        title: null,
        edu:{
            id:null,
            cid: "",
            bid: "",
            sksj: "",
            date1:"",
            date2:""
        }
    },
    created:function(){
        $.post(baseURL+"edu/attendance/options",function(r){

            vm.coptions=r.c;
            vm.boptions=r.b;
        });
    },
    methods: {

        query: function () {
           alert("未完待续...")
        },
        del: function () {
            var id = getSelectedRows();
            if(id == null){
                return ;
            }

            confirm('确定要删除选中的记录？', function(){
                $.ajax({
                    type: "POST",
                    url: baseURL + "edu/attendance/delete/",
                    contentType: "application/json",
                    data: JSON.stringify(id),
                    success: function(r){
                        if(r.code === 0){
                            alert('操作成功', function(){
                                vm.reload();
                            });
                        }else{
                            alert(r.msg);
                            vm.reload();
                        }
                    }
                });
            });
        },
        reload: function (event) {

            var page = $("#jqGrid").jqGrid('getGridParam','page');
            page ="1";
            $("#jqGrid").jqGrid('setGridParam',{
                postData:vm.edu,
                page:page
            }).trigger("reloadGrid");
        }
    }
});
